package com.crm.system.service.impl.userForumManager;

import com.crm.common.util.CommonUtils;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.entity.userForumManager.UserForumLike;
import com.crm.service.userForumManager.UserForumLikeDbService;
import com.crm.service.userForumManager.UserForumReplyDbService;
import com.crm.system.service.userForumManager.UserForumLikeService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Author:chaifuyou
 * @Date: 2021/5/24 9:37
 */
@Service
public class UserForumLikeServiceImpl implements UserForumLikeService {

    @Autowired
    private UserForumLikeDbService userForumLikeDbService;

    @Autowired
    private UserForumReplyDbService userForumReplyDbService;

    /**
     * 添加 点赞 收藏 转发
     * @param userForumLike
     */
    @Override
    public void addUserForumLike(UserForumLike userForumLike) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        userForumLike.setUserForumLikeId(CommonUtils.getGUID());
        userForumLike.setCreatePeopleId(userAccount.getAccountId());
        userForumLike.setCreateTm(new Date());
        userForumLikeDbService.addUserForumLike(userForumLike);
        //加阅读次数
        userForumReplyDbService.addReadNumberByUserForumId(userForumLike.getUserForumId());
    }

    /**
     * 取消 点赞 收藏 转发
     * @param userForumLike
     */
    @Override
    public void delUserForumLike(UserForumLike userForumLike) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        userForumLike.setCreatePeopleId(userAccount.getAccountId());
        userForumLikeDbService.delUserForumLike(userForumLike);
    }
}
